﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Inventory.sontemplate
{
    public partial class _ExaminPurchaseBill : Inventory.template.BasepurchaseBillFrom
    {
        List<string> pendingIDList;//待审核订单列表泛型集合
        ExaminPurchaseBillBLL bl;//审核页面业务逻辑类
        string opera;//记录操作类型 审核通过：YES 审核不通过：NO 
        public _ExaminPurchaseBill()
        {
            InitializeComponent();
            bl = new ExaminPurchaseBillBLL();
            lbPurchaseBill.Enabled = true;
        }
        /// <summary>
        /// 获取待审核订单列表
        /// </summary>
        /// <returns></returns>
        private List<string > GetPendingPurchaseBill()
        {
            pendingIDList =bl.GetPendingPurchaseBill();
            return pendingIDList;
        }
       /// <summary>
       /// 开始就可以见到左边框的数据
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>

        private void lbPurchaseBill_VisibleChanged(object sender, EventArgs e)
        {
            if (GetPendingPurchaseBill().Count == 0)
            {
                lbPurchaseBill.DataSource = null;

            }
            else
            {
                lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                lbPurchaseBill.SelectedIndex = -1;//变为未被选定状态
            }
        }
        private void GetValue()
        {
            bo = new PurchaseBill(); 
            bo.PurchaseBillID = txtPurchaseID.Text.Trim();
            bo.Examiner = "80001";
            bo.Memo = txtMemo.Text.Trim();
        }

        private void btnPass_Click(object sender, EventArgs e)
        {
            btnNoPass.Enabled = false;
            GetValue();
            opera = "YES";
        }
        private void btnNoPass_Click(object sender, EventArgs e)
        {
            btnNoPass.Enabled = false;
            GetValue();
            opera = "No";
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
         if(opera == "YES")
            if (bl.PassExamine (bo))
                {
                    MessageBox.Show("订单审核通过！", "系统提示");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                }
            if (opera == "No")
                if (bl.NoPassExamine(bo))
                {
                    MessageBox.Show("订单审核不通过！", "系统提示");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                }
            btnNoPass.Enabled = btnNoPass.Enabled = true;



        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            btnNoPass.Enabled = btnNoPass.Enabled = true;
            ClearControls.ClearControl(this);
            lbPurchaseBill.DataSource = GetPendingPurchaseBill();

        }
    }
}
